package org.tech4j.captcha.character.provider;

import org.tech4j.captcha.api.model.CaptchaEntity;
import org.tech4j.captcha.api.model.CaptchaResponse;
import org.tech4j.captcha.api.model.VoidFunction;
import org.tech4j.captcha.character.model.CharacterCaptchaEntity;
import org.tech4j.common.spi.SPI;

import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

/**
 * @program: tech4j
 * @description:
 * @author: YuKai Fan
 * @create: 2025/3/4 11:43
 **/
@SPI
public interface CaptchaProvider {

    /**
     * 验证码发送
     * @param captchaEntity
     */
    CaptchaResponse send(CharacterCaptchaEntity captchaEntity);

    /**
     * 验证码发送
     * @param captchaEntity
     * @param function
     */
    <R> CaptchaResponse send(CharacterCaptchaEntity captchaEntity, Function<CaptchaEntity, R> function);

    /**
     * 验证码验证
     * @param captchaEntity captchaEntity
     * @param supplier  supplier
     * @param function  function
     * @return CaptchaResponse
     */
    CaptchaResponse validate(CharacterCaptchaEntity captchaEntity, Supplier<String> supplier, VoidFunction function);

    /**
     * 验证码验证
     * @param captchaEntity captchaEntity
     * @param predicate predicate
     * @param function function
     * @return CaptchaResponse
     * @param <T>
     */
    CaptchaResponse validate(CharacterCaptchaEntity captchaEntity, Predicate<String> predicate, VoidFunction function);
}
